package com.zero.controller;

import com.zero.entity.Income;
import com.zero.entity.IncomeType;
import com.zero.service.IncomeService;
import com.zero.service.IncomeTypeService;
import com.zero.entity.Condition;
import com.zero.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/income")
public class IncomeController {

    @Autowired
    private IncomeService incomeService;

    @Autowired
    private IncomeTypeService incomeTypeService;

    @PostMapping("/type")
    public Result typeList(@RequestBody IncomeType incomeType, HttpServletRequest request){
        return incomeTypeService.select(incomeType, request);
    }

    @GetMapping("/type")
    public Result typeList(HttpServletRequest request){
        return incomeTypeService.select(request);
    }

    @PostMapping("/addType")
    public Result addType(@RequestBody IncomeType incomeType, HttpServletRequest request){
        return incomeTypeService.add(incomeType, request);
    }

    @GetMapping("/deleteType")
    public Result deleteType(@RequestParam("ids") String ids){
        return incomeTypeService.delete(ids);
    }

    @PostMapping("/updateType")
    public Result updateType(@RequestBody IncomeType incomeType){
        return incomeTypeService.update(incomeType);
    }


    @PostMapping("/list")
    public Result incomeList(@RequestBody Condition condition, HttpServletRequest request){
        return incomeService.select(condition, request);
    }

    @PostMapping("addIncome")
    public Result addIncome(@RequestBody Income income, HttpServletRequest request){
        return incomeService.add(income, request);
    }

    @GetMapping("/deleteIncome")
    public Result deleteIncome(@RequestParam("ids") String ids, HttpServletRequest request){
        return incomeService.delete(ids, request);
    }

    @PostMapping("/updateIncome")
    public Result updateIncome(@RequestBody Income income, HttpServletRequest request){
        return incomeService.update(income, request);
    }
}
